package com.isoftstone.project.buttjoint.controller;

import com.isoftstone.common.utils.JsonUtil;
import com.isoftstone.framework.controller.BaseController;

import com.isoftstone.project.buttjoint.domain.Data;
import com.isoftstone.project.buttjoint.domain.JsonSensor;
import com.isoftstone.project.buttjoint.domain.JsonStation;
import com.isoftstone.project.buttjoint.domain.MonitorTest;
import com.isoftstone.project.buttjoint.mapper.MonitorTestMapper;
import com.isoftstone.project.buttjoint.service.IMonitorTestService;
import com.isoftstone.project.device.sensor.domain.USensor;
import com.isoftstone.project.device.sensor.mapper.USensorMapper;
import com.isoftstone.project.device.station.domain.UStation;
import com.isoftstone.project.device.station.mapper.UStationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


import java.util.ArrayList;
import java.util.List;

/**
 * 井下最新数据Controller
 *
 */
@Controller
@RequestMapping("/json")
public class MonitorTestController extends BaseController {
    @Autowired
    MonitorTestMapper monitorTestMapper;
    @Autowired
    IMonitorTestService monitorTestService;
    @Autowired
    UStationMapper uStationMapper;
    @Autowired
    USensorMapper uSensorMapper;
    /**
     * 井下最新数据接口
     * @return
     */
    @RequestMapping(value = "/test",produces="text/html;charset=UTF-8")
    @ResponseBody
    public String test(){
        List<MonitorTest> monitorTestList=monitorTestService.selectAll();
        String json=  JsonUtil.writeListJSON(monitorTestList);
        System.out.println(json);
        return json;
    }
    /**
     * 井下历史数据接口
     * @return
     */
    @RequestMapping("/sjtest")
    @ResponseBody
    public String sjtest(String stationId,String startdate,String enddate,String type){
        List<MonitorTest> monitorTestList=monitorTestService.selectsjdata(stationId,startdate,enddate,type);
        String json=  JsonUtil.writeListJSON(monitorTestList);
        System.out.println(json);
        return json;
    }
    /**
     * 井下分站数据接口
     * @return
     */
    @RequestMapping("/sjstationtest")
    @ResponseBody
    public String sjstationtest(){
        List<UStation> uStationList=uStationMapper.selectstationst();
        List<JsonStation> jsonStationList=new ArrayList<>();
        for (UStation uStation : uStationList) {
            JsonStation jsonStation=new JsonStation();
            jsonStation.setStationId(uStation.getStationId());
            jsonStation.setStationName(uStation.getStationName());
            jsonStationList.add(jsonStation);
        }
        String json=  JsonUtil.writeListJSON(jsonStationList);
        System.out.println(json);
        return json;
    }
    /**
     * 井下传感器数据接口
     * @return
     */
    @RequestMapping("/sjsensortest")
    @ResponseBody
    public String sjsensortest(){
        List<USensor> uSensorList=uSensorMapper.selectsensorst();
        List<JsonSensor> jsonSensorList=new ArrayList<>();
        for (USensor uSensor : uSensorList) {
            JsonSensor jsonSensor=new JsonSensor();
            jsonSensor.setStationId(uSensor.getStationId());
            jsonSensor.setSensorId(String.valueOf(uSensor.getAutoid()));
            jsonSensor.setSensorName(uSensor.getSensorTypeName());
            jsonSensorList.add(jsonSensor);
        }
        String json=  JsonUtil.writeListJSON(jsonSensorList);
        System.out.println(json);
        return json;
    }
}
